package io.github.tangwan.jdk8;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author tangwan
 * @version V1.0
 * created on 2022/1/10 15:13
 * @since JDK 1.8
 */
@NoArgsConstructor
@Data
public class Database {

    private String name;
    private Integer compatibilityLevel;
    private String createdTimestamp;
    private String lastUpdate;
    private String lastSchemaUpdate;
    private String lastProcessed;
    private ModelDTO model;

    @NoArgsConstructor
    @Data
    public static class ModelDTO {
        private String culture;
        private DataAccessOptionsDTO dataAccessOptions;
        private String defaultPowerBIDataSourceVersion;
        private String sourceQueryCulture;
        private String modifiedTime;
        private String structureModifiedTime;
        private List<TablesDTO> tables;
        private List<RelationshipsDTO> relationships;
        private List<CulturesDTO> cultures;
        private List<AnnotationsDTO> annotations;

        @NoArgsConstructor
        @Data
        public static class DataAccessOptionsDTO {
            private Boolean legacyRedirects;
            private Boolean returnErrorValuesAsNull;
        }

        @NoArgsConstructor
        @Data
        public static class TablesDTO {
            private String name;
            private String lineageTag;
            private String modifiedTime;
            private String structureModifiedTime;
            private List<ColumnsDTO> columns;
            private List<PartitionsDTO> partitions;
            private List<MeasuresDTO> measures;
            private List<AnnotationsDTO> annotations;
            private Boolean isHidden;
            private Boolean isPrivate;
            private List<HierarchiesDTO> hierarchies;
            private Boolean showAsVariationsOnly;

            @NoArgsConstructor
            @Data
            public static class ColumnsDTO {
                private String type;
                private String name;
                private String dataType;
                private Boolean isHidden;
                private Boolean isUnique;
                private Boolean isKey;
                private Boolean isNullable;
                private String modifiedTime;
                private String structureModifiedTime;
                private String refreshedTime;
                private AttributeHierarchyDTO attributeHierarchy;
                private List<AnnotationsDTO> annotations;
                private String sourceColumn;
                private String sourceProviderType;
                private String lineageTag;
                private String summarizeBy;
                private String formatString;

                @NoArgsConstructor
                @Data
                public static class AttributeHierarchyDTO {
                    private String state;
                    private String modifiedTime;
                    private String refreshedTime;
                }

                @NoArgsConstructor
                @Data
                public static class AnnotationsDTO {
                    private String name;
                    private String value;
                    private String modifiedTime;
                }
            }

            @NoArgsConstructor
            @Data
            public static class PartitionsDTO {
                private String name;
                private String mode;
                private String state;
                private String modifiedTime;
                private String refreshedTime;
                private SourceDTO source;

                @NoArgsConstructor
                @Data
                public static class SourceDTO {
                    private String type;
                    private String expression;
                }
            }

            @NoArgsConstructor
            @Data
            public static class MeasuresDTO {
                private String name;
                private String expression;
                private String formatString;
                private String lineageTag;
                private String dataType;
                private String modifiedTime;
                private String structureModifiedTime;
                private List<AnnotationsDTO> annotations;

                @NoArgsConstructor
                @Data
                public static class AnnotationsDTO {
                    private String name;
                    private String value;
                    private String modifiedTime;
                }
            }

            @NoArgsConstructor
            @Data
            public static class AnnotationsDTO {
                private String name;
                private String value;
                private String modifiedTime;
            }

            @NoArgsConstructor
            @Data
            public static class HierarchiesDTO {
                private String name;
                private String lineageTag;
                private String state;
                private String modifiedTime;
                private String structureModifiedTime;
                private String refreshedTime;
                private List<LevelsDTO> levels;
                private List<AnnotationsDTO> annotations;

                @NoArgsConstructor
                @Data
                public static class LevelsDTO {
                    private String name;
                    private Integer ordinal;
                    private String column;
                    private String lineageTag;
                    private String modifiedTime;
                }

                @NoArgsConstructor
                @Data
                public static class AnnotationsDTO {
                    private String name;
                    private String value;
                    private String modifiedTime;
                }
            }
        }

        @NoArgsConstructor
        @Data
        public static class RelationshipsDTO {
            private String name;
            private String fromTable;
            private String fromColumn;
            private String toTable;
            private String toColumn;
            private String state;
            private String modifiedTime;
            private String refreshedTime;
            private String toCardinality;
            private Boolean isActive;
            private String joinOnDateBehavior;
        }

        @NoArgsConstructor
        @Data
        public static class CulturesDTO {
            private String name;
            private String modifiedTime;
            private String structureModifiedTime;
            private LinguisticMetadataDTO linguisticMetadata;

            @NoArgsConstructor
            @Data
            public static class LinguisticMetadataDTO {
                private ContentDTO content;
                private String contentType;
                private String modifiedTime;

                @NoArgsConstructor
                @Data
                public static class ContentDTO {
                    private String version;
                    private String language;
                    private String dynamicImprovement;
                }
            }
        }

        @NoArgsConstructor
        @Data
        public static class AnnotationsDTO {
            private String name;
            private String value;
            private String modifiedTime;
        }
    }
}
